package com.zbp.config.exception;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * packageName com.zbp.config.exception
 *
 * @author zbp
 * @version JDK 8
 * @fileName GlobalExceptionHandler.java
 * @date 2023-11-16
 * @description 统一异常处理，根据自定义异常分别处理错误信息
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    // 根据实际自定义的异常统一处理
    @ExceptionHandler(value = Exception.class)
    public Result<Boolean> globalException(Exception e) {
        log.error("GlobalExceptionHandler异常[{}]", e.getMessage());
        return Result.failure(ResultCode.FAIL, e.getMessage());
    }

    // 根据实际自定义的异常统一处理
    @ExceptionHandler(value = ApiException.class)
    public Result<Boolean> globalException(ApiException e) {
        log.error("GlobalExceptionHandler异常[{}]", e.getMessage());
        return Result.failure(ResultCode.FAIL, e.getMessage());
    }

}
